<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加管理员</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__CSS__/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__CSS__/animate.min.css" rel="stylesheet">
    <link href="__CSS__/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="__CSS__/style.min.css?v=4.1.0" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-8">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加管理员</h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="commentForm" method="post" action="{:url('company/useradd')}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">公司名称：</label>
                            <div class="input-group col-sm-4">
                                <input id="name" type="text" class="form-control" name="name" required="" aria-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">负责人：</label>
                            <div class="input-group col-sm-4">
                                <input id="manager" type="text" class="form-control" name="manager" required="" aria-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">负责人手机：</label>
                            <div class="input-group col-sm-4">
                                <input id="mobile" type="text" class="form-control" name="mobile" required="" aria-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">省：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control" name="province" id="province" class="form-control">
                                    <option value="">请选择</option>
                                    {volist name="area" id="vo"}
                                    <option value="{$vo.area_id}">{$vo.area_name}
                                            </option>
                                    {/volist}
                                </select>
                            </div>
                            <label class="col-sm-3 control-label">市：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control" name="city" id="city" class="form-control">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                            <label class="col-sm-3 control-label">区：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control" name="dist" id="dist">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">详细地址：</label>
                            <div class="input-group col-sm-4">
                                <input id="address" type="text" class="form-control" name="address" required="" aria-required="true">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">上级代理：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control" name="top_cid" required="" aria-required="true">
                                    <option value="">请选择</option>
                                    {if !empty($company)}
                                    {foreach name="company" item="vo"}
                                    <option value="{$vo.id}">{$vo.name}</option>
                                    {/foreach}
                                    {/if}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">管理员角色：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control" name="role_id" required="" aria-required="true">
                                    <option value="">请选择</option>
                                    {if !empty($role)}
                                    {foreach name="role" item="vo"}
                                    <option value="{$vo.id}">{$vo.role_name}</option>
                                    {/foreach}
                                    {/if}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">登录密码：</label>
                            <div class="input-group col-sm-4">
                                <input id="password" type="text" class="form-control" name="password" required="" aria-required="true">
                            </div>
                        </div>
                        <!-- <div class="form-group">
                            <label class="col-sm-3 control-label">后台用户名：</label>
                            <div class="input-group col-sm-4">
                                <input id="real_name" type="text" class="form-control" name="real_name" required="" aria-required="true">
                            </div>
                        </div> -->
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否启用：</label>
                            <div class="input-group col-sm-6">
                                {foreach name='status' item='vo' key='key'}
                                <div class="radio i-checks col-sm-4">
                                    <label>
                                        <input type="radio" value="{$key}" {if condition="$key == 1 " }checked{/if} name="status"> <i></i> {$vo}</label>
                                </div>
                                {/foreach}
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-6">
                                <!--<input type="button" value="提交" class="btn btn-primary" id="postform"/>-->
                                <button class="btn btn-primary" type="submit">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
<script src="__JS__/jquery.min.js?v=2.1.4"></script>
<script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
<script src="__JS__/content.min.js?v=1.0.0"></script>
<script src="__JS__/plugins/validate/jquery.validate.min.js"></script>
<script src="__JS__/plugins/validate/messages_zh.min.js"></script>
<script src="__JS__/plugins/iCheck/icheck.min.js"></script>
<script src="__JS__/plugins/layer/laydate/laydate.js"></script>
<script src="__JS__/plugins/layer/layer.min.js"></script>
<script src="__JS__/jquery.form.js"></script>
<script type="text/javascript">

function getSelectVal(area,next) {
    //获取后台json数据
        $.getJSON("/activity/ceshi", {
            bigname: $("#"+area).val()
        }, function(json) {
            var smallname = $("#"+next);
            $("option", smallname).remove(); //清空原有的选项
                var option = "<option>请选择</option>";
                $.each(json, function(index, array) {
                    option += "<option value='" + array['area_id'] + "'>" + array['area_name'] + "</option>";
                smallname.html(option);
            });
        });
    }

// 选择上级菜单选项触发事件
$(function() {
    // getSelectVal('province','city');
    // getSelectVal('city','dist');
    $("#province").change(function() {
        getSelectVal('province','city');
    });
    $("#city").change(function() {
        getSelectVal('city','dist');
    });
});

    var index = '';
    function showStart(){
        index = layer.load(0, {shade: false});
        return true;
    }

    function showSuccess(res){
        layer.ready(function(){
            layer.close(index);
            if(1 == res.code){
               layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
                   window.location.href = res.data;
               });
            }else if(111 == res.code){
                window.location.reload();
            }else{
                layer.msg(res.msg, {anim: 6});
            }
        });
    }

    $(document).ready(function(){
        $(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});

        // 添加管理员
        var options = {
            beforeSubmit:showStart,
            success:showSuccess
        };

        $('#commentForm').submit(function(){
            $(this).ajaxSubmit(options);
            return false;
        });
    });

    // 表单验证
    $.validator.setDefaults({
        highlight: function(e) {
            $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
        },
        success: function(e) {
            e.closest(".form-group").removeClass("has-error").addClass("has-success")
        },
        errorElement: "span",
        errorPlacement: function(e, r) {
            e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
        },
        errorClass: "help-block m-b-none",
        validClass: "help-block m-b-none"
    });

</script>
</body>
</html>
